<template>
  <div>

    <h3 style="text-align: center;">销售信息查询</h3>
    <div style="height:250px">
      <el-table :data="cutObj.records" style="width: 100%" border stripe>
        <el-table-column prop="client.name" label="客户名称"/>
        <el-table-column prop="user.realName" label="销售员"/>
        <el-table-column prop="createDate" label="销售时间"/>
        <el-table-column prop="totalPrice" label="订单总价"/>
        <el-table-column fixed="right" label="操作">
          <template #default="scope">
            <el-button type="danger" size="small" @click="findById(scope.row.id)">查看详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="margin: 20px">
      <el-pagination
          v-model:current-page="currentPage"
          v-model:page-size="cutObj.size"
          background
          layout="prev, pager, next, jumper"
          :total="cutObj.total"
          @current-change="findByItem"
      />
    </div>
    <div style="display: flex;justify-content: space-around">
      <div>
        客户名称：
        <el-input v-model="name" style="width: 200px"/>
        <br>
        起始日期：
        <el-input type="date" v-model="startDate" style="width: 200px"/>
        <br>
        结束日期：
        <el-input type="date" v-model="endDate" style="width: 200px"/>
        <br>
        <el-button type="primary" @click="findByItem(1)">查询</el-button>
      </div>
    </div>
    <!--点击查看详情弹出-->
    <!--  查看-->
    <el-dialog
        v-model="showId"
        title="采购信息详情"
        width="40%"
    >

      <el-row>
        <el-col :span="6"><span>客户名称</span></el-col>
        <el-col :span="18"><span>{{ nameObj.name}}</span></el-col>
      </el-row>
      <el-row>
        <el-col :span="6"><span>销售员</span></el-col>
        <el-col :span="18"><span>{{ userObj.realName}}</span></el-col>
      </el-row>
      <el-row>
        <el-col :span="6"><span>销售日期</span></el-col>
        <el-col :span="18"><span>{{sellOrderObj.createDate}}</span></el-col>
      </el-row>
      <el-row>
        <el-col :span="6"><span>订单金额</span></el-col>
        <el-col :span="18"><span>{{sellOrderObj.totalPrice}}</span></el-col>
      </el-row>
      <el-row>
        <el-col :span="6"><span>送货地址</span></el-col>
        <el-col :span="18"><span>{{sellOrderObj.address}}</span></el-col>
      </el-row>

      <el-row>
        <el-col :span="6"><span>出库物品明细</span></el-col>
        <el-col :span="18"></el-col>
      </el-row>


      <el-table :data="sellOrderObj.saleOrderInfoList" style="width: 100%" border stripe>
        <el-table-column prop="product.name" label="商品名称"/>
        <el-table-column prop="product.brand" label="品牌"/>
        <el-table-column prop="price" label="成交价"/>
        <el-table-column prop="num" label="销售数量"/>
      </el-table>

      <el-row>
        <el-col :span="12"></el-col>
        <el-col :span="12">
          <el-button type="primary" @click="showId=false">
            确定
          </el-button>
        </el-col>
      </el-row>
    </el-dialog>

  </div>
</template>

<script>
import axios from "axios";

export default {
  data() {
    return {
      showId:false,
      currentPage:1,
      cutObj:{},
      name:"",
      startDate:"",
      endDate:"",

      sellOrderObj: {},
      userObj:{},
      nameObj:{},
    }
  },methods:{
    findByItem(pageNO){
      this.currentPage = pageNO
      axios.get("/project/saleOrderInfo/findByItem",{
        params:{
          pageNO,
          clientName:this.name,
          startDate:this.startDate,
          endDate:this.endDate
        }
      }).then(resp=>{
        this.cutObj = resp.data
      })
    },
    findById(saleOrderId){
      this.showId = true;
      axios.get("/project/saleOrderInfo/findByOrderId",{
        params:{
          saleOrderId
        }
      }).then(resp=>{
        this.sellOrderObj = resp.data
        this.nameObj = resp.data.client
        this.userObj = resp.data.user
      })
    }
  },created() {
    this.user = JSON.parse(sessionStorage.getItem("loginUser"));
    this.findByItem(1)
  }
}
</script>

<style scoped>

</style>